
from apps.common.base.serializers import *
from apps.system.learn.models import *

class LearnBaseSerializer(BaseSerializer):

    class Meta:
        model = Learn
        fields = "__all__"
        extra_kwargs = {
            'price': {'required': True,'read_only': True},
        }

class LearnModelSerializer(BaseSerializer):

    userList = serializers.SerializerMethodField()
    def get_userList(self, obj):
        try:
            return [{'id': obj.id, 'code': obj.code, 'username': obj.username} for obj in obj.users.all()]
        except:
            return []

    statusLabel = serializers.SerializerMethodField()

    def get_statusLabel(self, obj):
        try:
            return obj.get_status_display()
        except:
            return '未知'

    class Meta:
        model = Learn
        fields = "__all__"
        